package com.yanfan.ccapicode.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yanfan.ccapicode.dao.DeviceRepository;
import com.yanfan.ccapicode.dao.base.repository.BaseRepository;
import com.yanfan.ccapicode.dao.entity.DeviceDO;
import com.yanfan.ccapicode.dao.mapper.CcapiDeviceMapper;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * :)
 *
 */
@Repository
public class DeviceRepositoryImpl extends BaseRepository<CcapiDeviceMapper, DeviceDO,Object> implements DeviceRepository {

    @Override
    public List<DeviceDO> selectByThirdDeviceIdsClient(String clientId, List<String> thirdDeviceIds) {
        LambdaQueryWrapper<DeviceDO> lambda = new QueryWrapper<DeviceDO>().lambda();
        lambda.in(DeviceDO::getThirdDeviceId, thirdDeviceIds);
        lambda.eq(DeviceDO::getClientId, clientId);
        return this.baseMapper.selectList(lambda);
    }

    @Override
    public List<DeviceDO> selectByClientId(String clientId) {
        LambdaQueryWrapper<DeviceDO> lambda = new QueryWrapper<DeviceDO>().lambda();
        lambda.eq(DeviceDO::getClientId, clientId);
        return this.baseMapper.selectList(lambda);
    }

    @Override
    public List<DeviceDO> selectByTokenKey(String tokenKey) {
        LambdaQueryWrapper<DeviceDO> lambda = new QueryWrapper<DeviceDO>().lambda();
        lambda.eq(DeviceDO::getTokenKey, tokenKey);
        return this.baseMapper.selectList(lambda);
    }

    @Override
    public List<DeviceDO> selectByRefreshKeys(List<String> refreshTokenKeys) {
        LambdaQueryWrapper<DeviceDO> lambda = new QueryWrapper<DeviceDO>().lambda();
        lambda.in(DeviceDO::getRefreshTokenKey, refreshTokenKeys);
        return this.baseMapper.selectList(lambda);
    }


    /**
     * 查询云云对接设备
     *
     * @param id 云云对接设备主键
     * @return 云云对接设备
     */
    @Override
    public DeviceDO selectCcapiDeviceById(Long id) {
        return baseMapper.selectCcapiDeviceById(id);
    }

    /**
     * 查询云云对接设备列表
     *
     * @param ccapiDevice 云云对接设备
     * @return 云云对接设备
     */
    @Override
    public List<DeviceDO> selectCcapiDeviceList(DeviceDO ccapiDevice) {
        return baseMapper.selectCcapiDeviceList(ccapiDevice);
    }

}
